/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukumagic.
 *
 * jukumagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukumagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukumagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "common.h"
#include "projectsettingsdialog.h"

/*enum
{
	ID_OK
};*/

BEGIN_EVENT_TABLE(ProjectSettingsDialog, wxDialog)
	EVT_BUTTON(wxID_ANY, ProjectSettingsDialog::OnButton)
END_EVENT_TABLE()
            
ProjectSettingsDialog::ProjectSettingsDialog(wxWindow *parent, Project *project)
: wxDialog(parent, wxID_ANY, wxString(_T("Project settings")))
{
	//std::cout<<"ProjectSettingsDialog::ProjectSettingsDialog()"<<std::endl;
	m_project = project;
	if(m_project == NULL) return;
	if(m_project->m_board == NULL) return;

	wxBoxSizer *ts = new wxBoxSizer(wxVERTICAL);

	//options grid sizer
	
	wxFlexGridSizer *fg = new wxFlexGridSizer(0, 2, 5, 5);
	wxStaticText *st;
	
	//the options

	/*st = new wxStaticText(this, wxID_ANY, wxT("Project name"),
			wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
	fg->Add(st, 1, wxALIGN_RIGHT | wxALL, 5);
	m_nametc = new wxTextCtrl(this, wxID_ANY, m_project->m_name,
			wxDefaultPosition, wxSize(200, -1));
	fg->Add(m_nametc, 1, wxEXPAND, 0);*/

	st = new wxStaticText(this, wxID_ANY, wxT("Board width"),
			wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
	fg->Add(st, 1, wxALIGN_RIGHT | wxALL, 5);
	m_wtc = new wxTextCtrl(this, wxID_ANY,
			wxString::Format(wxT("%d"), m_project->m_board->GetW()),
			wxDefaultPosition, wxSize(200, -1));
	fg->Add(m_wtc, 1, wxEXPAND, 0);

	st = new wxStaticText(this, wxID_ANY, wxT("Board height"),
			wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
	fg->Add(st, 1, wxALIGN_RIGHT | wxALL, 5);
	m_htc = new wxTextCtrl(this, wxID_ANY,
			wxString::Format(wxT("%d"), m_project->m_board->GetH()),
			wxDefaultPosition, wxSize(200, -1));
	fg->Add(m_htc, 1, wxEXPAND, 0);

	//

	ts->Add(fg, 1, wxEXPAND | wxALL, 5);

	//bottom buttons

	wxBoxSizer *bs = new wxBoxSizer(wxHORIZONTAL);
	m_okb = new wxButton(this, wxID_OK, wxT("&OK"));
	m_cab = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
	bs->Add(m_okb, 0, wxALIGN_CENTER | wxALL, 5);
	bs->Add(m_cab, 0, wxALIGN_CENTER | wxALL, 5);

	ts->Add(bs, 0, wxALIGN_RIGHT, 5);

	//other
	SetSizer(ts);
	ts->SetSizeHints(this);
	ts->Fit(this);
	m_okb->SetFocus();
	m_okb->SetDefault();
}

void ProjectSettingsDialog::OnButton(wxCommandEvent &event)
{
	if(event.GetEventObject() == m_okb){
		if(m_project){
			//m_project->m_name = m_nametc->GetValue();
			if(m_project->m_board){
				long t;
				if(m_wtc->GetValue().ToLong(&t)) m_project->m_board->SetW(t);
				if(m_htc->GetValue().ToLong(&t)) m_project->m_board->SetH(t);
			}
		}
	}
	event.Skip();
}

